unit uProperties;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrlsEh, DBCtrls, ExtCtrls, ComCtrls, ToolWin,
  Grids, DB, DBGridEh;

type
  TfProperties = class(TForm)
    Panel1: TPanel;
    Bevel1: TBevel;
    Panel2: TPanel;
    Button1: TButton;
    GroupBox1: TGroupBox;
    DBGridEh5: TDBGridEh;
    tbAgreementOperationParamColor: TToolBar;
    tbAddAgreementOperationParamColor: TToolButton;
    tbDelAgreementOperationParamColor: TToolButton;
    procedure DBGridEh5KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure DBGridEh5GetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
  private
    { Private declarations }
  public
    procedure SetDataSet(ACaption: String; ADataSource: TDataSource);
  end;

var
  fProperties: TfProperties;

implementation

uses uDBData;

{$R *.dfm}

procedure TfProperties.SetDataSet(ACaption: String; ADataSource: TDataSource);
begin
  Caption := ACaption;
  DBGridEh5.DataSource := ADataSource;
end;

procedure TfProperties.DBGridEh5KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #13 then (Sender as TDBGridEh).DataSource.DataSet.Post;
end;

procedure TfProperties.Button1Click(Sender: TObject);
begin
  Close();
end;

procedure TfProperties.DBGridEh5GetCellParams(Sender: TObject;
  Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
begin
  if ((not (Sender as TDBGridEh).DataSource.DataSet.IsEmpty)and((Sender as TDBGridEh).DataSource.DataSet.State <> dsEdit)and((Sender as TDBGridEh).DataSource.DataSet.State <> dsInsert)) then
  begin
    fDBData.dOperationParamColor.DataSet.Filtered := False;
    fDBData.dOperationParamColor.DataSet.Filter := 'Name=' + QuotedStr(UpperCase((Sender as TDBGridEh).DataSource.DataSet.FieldByName('IsFinished').AsString));
    fDBData.dOperationParamColor.DataSet.Filtered := True;
    if(not fDBData.dOperationParamColor.DataSet.IsEmpty) then
    begin
      AFont.Color := fDBData.dOperationParamColor.DataSet.FieldByName('FontColor').AsInteger;
      Background := fDBData.dOperationParamColor.DataSet.FieldByName('BGColor').AsInteger;
    end;
    fDBData.dOperationParamColor.DataSet.Filtered := False;
    fDBData.dOperationParamColor.DataSet.Filter := '';
  end;
end;

end.
